package com.leyou.order.controller;

import com.leyou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private OrderService orderService;

    @PostMapping(value = "/wx/notify", produces = "application/xml")
    public Map<String, String> receiveWxNodeResult(@RequestBody Map<String, String> resultMap){
        orderService.handlerOrder(resultMap);
        //注意：这时客户的钱已经付了，直接告诉微信成功了就可以了，不用再随便抛异常。
        Map<String, String> helloMap = new HashMap<>();
        helloMap.put("return_code", "SUCCESS");
        helloMap.put("return_msg", "OK");
        return helloMap;
    }

}
